﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Globalization;
using System.Resources;

namespace SampleResourceBundle
{
    public partial class Form1 : Form
    {
        private ResourceBundle resBundle;

        public Form1()
        {
            InitializeComponent();

            resBundle = ResourceBundle.GetInstance();
        }

        public override void Refresh()
        {
            this.Text = resBundle.GetString("Form1", "title");
            this.m_lbl1.Text = resBundle.GetString("Form1", "helloText");
            this.m_btn1.Text = resBundle.GetString("Form1", "buttonText");

            m_langue.Text = resBundle.GetString("Form1", "changeLanguage");

            base.Refresh();
        }

        private void fillAppLangueCombo()
        {
            CultureInfo enCulture = new CultureInfo(SpecificCultures.EN_US);
            CultureInfo zhCulture = new CultureInfo(SpecificCultures.ZH_CN);
            m_langue.Items.Add(enCulture);
            m_langue.Items.Add(zhCulture);
        }


        private void m_btn1_Click(object sender, EventArgs e)
        {
            new Form2().ShowDialog();
        }

        private void m_langue_SelectedIndexChanged(object sender, EventArgs e)
        {
            CultureInfo culture = (CultureInfo)m_langue.SelectedItem;

            //inform resourceBundle of the locale change
            resBundle.Locale = culture.Name;

            Application.CurrentCulture = culture;

            //let's remember user's setting for culture
            Properties.Settings.Default.LastCulture = culture.Name;
            Properties.Settings.Default.Save();
            
            this.Refresh();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ///////////////////////////
            //This has to be called at Load to put the correct language in 
            this.Refresh();
            //////////////////////////

            fillAppLangueCombo();
        }
    }
}
